package dletc.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

//学习线程池
public class ThreadPool {
    public static void main(String[] args) {
        //1.创建线程池
        ExecutorService service = Executors.newFixedThreadPool(10);
        //2.开启线程 execute() 没有返回值  submit()有返回值
        service.execute(new TestThreadPool());
        service.execute(new TestThreadPool());
        service.execute(new TestThreadPool());
        service.execute(new TestThreadPool());

        service.submit(new TestThreadPool());
        service.submit(new TestThreadPool());
        service.submit(new TestThreadPool());
        Future<?> submit = service.submit(new TestThreadPool());
        System.out.println(submit);
        //3.关闭线程池
        service.shutdownNow();
    }
}

class TestThreadPool implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
    }
}
